package com.example.food.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.food.bean.OrderListBean;
import com.example.home.R;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class FoodAdapter extends  RecyclerView.Adapter<FoodAdapter.MyHolder>{
    private Context context ;
    private List<OrderListBean.RowsBean.OrderInfoBean.OrderItemListBean> list;

    public FoodAdapter(Context context, List<OrderListBean.RowsBean.OrderInfoBean.OrderItemListBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public FoodAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        View view = LayoutInflater.from(context).inflate(R.layout.item_foodlist,null);
        return new FoodAdapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FoodAdapter.MyHolder holder, int position) {
        String productImage = list.get(position).getProductImage();
        Glide.with(context).load(ip +productImage).into(holder.productImage);
        holder.productName.setText(list.get(position).getProductName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView productImage;
        TextView productName;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            productImage = itemView.findViewById(R.id.imgurl);
            productName = itemView.findViewById(R.id.cainame);

        }
    }
}
